<?php require ROOT_PATH . 'views/layouts/header.php'; ?>

<div class="container main-content">

    <?php if (!empty($notifications)): ?>
    <div class="notifications-container">
        <h3>未读消息</h3>
        <?php foreach ($notifications as $notification): ?>
            <div class="notification-item">
                <p><?php echo $notification['message']; ?></p>
                <div class="notification-actions">
                    <a href="<?php echo htmlspecialchars($notification['link'], ENT_QUOTES, 'UTF-8'); ?>">查看动态</a>
                    <form action="/notification/read/<?php echo $notification['id']; ?>" method="post" style="display:inline;">
                        <button type="submit" class="button-link">标记为已读</button>
                    </form>
                </div>
            </div>
        <?php endforeach; ?>
    </div>
    <?php endif; ?>


    <div class="tweet-form-container">
        <h3>有什么新鲜事？</h3>
        <form action="/tweet/create" method="post">
            <textarea name="content" rows="3" placeholder="在这里输入内容..." required></textarea>
            <button type="submit">发布</button>
        </form>
    </div>

    <div class="timeline">
        <h2>我的时间线</h2>
        <?php
        if (empty($tweets)) {
            echo "<p>这里空空如也。去关注一些人，或者发布你的第一条动态吧！</p>";
        } else {
            foreach ($tweets as $tweet) {
                // 引入可复用的推文视图组件
                require ROOT_PATH . 'views/_tweet.php';
            }
        }
        ?>
    </div>
</div>

<?php require ROOT_PATH . 'views/layouts/footer.php'; ?>
